package com.alcloud.springplus.controller;

import com.alcloud.springplus.base.GenericService;
import com.alcloud.springplus.base.ResponseCode;
import com.alcloud.springplus.base.ResponseData;
import com.alcloud.springplus.constants.Constants;
import com.alcloud.springplus.domain.Dict;
import com.alcloud.springplus.service.DictService;
import com.alcloud.springplus.util.ServletUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
  *
  * @className:      DictController
  * @description:    数据字典接口类
  * @date:           2018/12/10 14:12
  * @author:         AllG
  * @updateRemark:   更新说明
 */
@RestController
@RequestMapping("dict")
public class DictController extends GenericController<Dict,Long>{

    private final static Logger logger = LoggerFactory.getLogger(DictController.class);

    @Autowired
    private DictService dictService;

    public DictController(GenericService<Dict, Long> genericService) {
        super(genericService);
    }


    /**
     * @method  searchWithChildren
     * @description 查询附带子节点的数据字典信息
     * @date: 2018/12/12 9:18
     * @author: AllG
     * @param pageable
     * @param request
     * @return com.alcloud.springplus.base.ResponseData<org.springframework.data.domain.Page<com.alcloud.springplus.domain.Dict>>
     */
    @GetMapping("/search-with-children")
    public ResponseData<Page<Dict>> searchWithChildren(@PageableDefault(sort = {"id"}, direction = Sort.Direction.DESC) Pageable pageable, HttpServletRequest request){
        //获取查询条件数据
        return new ResponseData<>(ResponseCode.SUCCESS,dictService.findAllWithChildren(ServletUtils.getParamValuesMap(request, Constants.SEARCH_PREFIX),pageable));
    }

}
